import org.dreamwork.jasmine2.web.client.UserAgentParser;

import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-11-28
 * Time: 上午10:57
 */

public class FileTest {
    private static final String[] uas = {
        // opera
/*
        "Opera/9.80 (Windows NT 6.1; WOW64; U; zh-cn) Presto/2.10.229 Version/11.62",
        "Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.10.229 Version/11.62",
        "Opera/9.80 (Android 2.2; Linux; Opera Tablet/ADR-1204201824; U; zh-cn) Presto/2.10.254 Version/12.00",
        "Opera/9.80 (X11; Linux x86_64; U; zh-cn) Presto/2.7.62 Version/11.01",
        "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.7; U; zh-cn) Presto/2.10.229 Version/11.62",

        // ie family
        "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; 360SE)",
        "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)",
        "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; InfoPath.2; 360SE)",
*/
        "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MDDC; Media Center PC 6.0; InfoPath.3; Tablet PC 2.0; .NET4.0C)",

        // firefox
/*
        "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0",
        "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.12) Gecko/2009072711 CentOS/3.0.12-1.el5.centos Firefox/3.0.12",
        "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0",
        "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",

        // webkit family
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19",
        "Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; GT-P1000 Build/FROYO) UC AppleWebKit/530+ (KHTML, like Gecko) Mobile Safari/530",
        "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3",
        "Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3",
        "Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10",
        "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.12 (KHTML, like Gecko) Maxthon/3.3.6.2000 Chrome/18.0.966.0 Safari/535.12",
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.9 (KHTML, like Gecko) Chrome/20.0.1115.1 Safari/536.9",
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
        "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; zh-cn) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
        "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16",
        "Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; MOT-XT883/SLNCT-60.3.250; 540*960; CTC/2.0) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
*/
    };
    public static void main (String[] args) throws Exception {
//        userAgentTest ();
/*
        UserAgentParser parser = new UserAgentParser ();
        for (String us : uas) {
            System.out.println (parser.parse (us));
        }
*/
/*
        Calendar c = Calendar.getInstance ();
        long now = c.getTimeInMillis ();
        c.add (Calendar.YEAR, 1);
        long nextYear = c.getTimeInMillis ();
        System.out.println ((nextYear - now) / 1000);
*/
        URL url = new URL ("classpath://org.dreamwork.jasmine2.editor.ckeditor.controls.CKEditorControl");
        System.out.println (url.getProtocol ());

        java.io.FileInputStream fin = new java.io.FileInputStream ("a.txt");
        int c = System.in.read ();
        fin.close ();
        System.exit (0);
    }

    public static void userAgentTest () throws Exception {


//        Pattern p = Pattern.compile ("^(.*?)\\/(\\d+?)\\.(\\d+?)\\s\\((.*?);")
//        Pattern ie = Pattern.compile ("^Mozilla\\/[\\d\\.]+\\s\\(compatible; MSIE ([\\d\\.]+);\\sWindows( NT )?\\s*([\\d\\.]+);(\\sWOW64;)?\\sTrident\\/([\\d\\.]+).*$");

//        Pattern opera = Pattern.compile ("^Opera.*?Presto\\/([\\d\\.]+)\\sVersion\\/([\\d\\.]+).*$");
//        UserAgent agent = new UserAgent ();
//        Pattern firefox = Pattern.compile ("^Mozilla.*?Gecko\\/([\\d]+).*?Firefox\\/([\\d\\.]+).*$");
//        Pattern chrome = Pattern.compile ("^Mozilla\\/.*?\\(.*?AppleWebKit\\/([\\d\\.\\+]+)\\s*\\(KHTML, like Gecko\\).*?Chrome\\/([\\d\\.]+).*?Safari\\/([\\d\\.]+).*$");
//        Pattern android_browser = Pattern.compile ("^Mozilla\\/.*?\\(Linux; U; Android.*?AppleWebKit\\/([\\d\\.\\+]+)\\s*\\(KHTML, like Gecko\\).*?(Version\\/([\\d\\.]+))? Mobile Safari\\/[\\d\\.]+.*?");
//        "Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3",
//        Pattern safari = Pattern.compile ("^Mozilla\\/.*?\\(iPhone.*?AppleWebKit\\/([\\d\\.\\+]+)\\s*\\(KHTML, like Gecko\\).*?Version\\/([\\d\\.]+) Mobile\\/.*?Safari\\/[\\d\\.]+.*?", Pattern.CASE_INSENSITIVE);
//                Pattern.compile ("^Mozilla\\/.*?AppleWebKit\\/([\\d\\.\\+]+)\\s*\\(KHTML, like Gecko\\).*?Version\\/([\\d\\.]+).*?Safari\\/[\\d\\.]+.*?$");
        for (String ua : uas) {
            Matcher m = UserAgentParser.IE_PATTERN.matcher (ua);
            if (m.matches ()) {
                System.out.println (ua);
                int groups = m.groupCount ();
                for (int i = 1; i <= groups; i ++)
                    System.out.printf ("group[%d]=%s%n", i, m.group (i));
                System.out.println ();
            }
        }
    }
}
